home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / scsiDiskBoot / RCS / fileLoad.c,v < prev    next >
Encoding:
Text File  |  1989-06-12  |  6.9 KB  |  364 lines

  1. head     1.7;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    mendel:1.7; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.7
  10. date     89.01.06.08.14.27;  author brent;  state Exp;
  11. branches ;
  12. next     1.6;
  13.  
  14. 1.6
  15. date     87.05.27.14.32.39;  author brent;  state Exp;
  16. branches ;
  17. next     1.5;
  18.  
  19. 1.5
  20. date     87.05.11.11.14.56;  author brent;  state Exp;
  21. branches ;
  22. next     1.4;
  23.  
  24. 1.4
  25. date     86.07.24.11.46.42;  author brent;  state Exp;
  26. branches ;
  27. next     1.3;
  28.  
  29. 1.3
  30. date     86.07.21.09.33.43;  author brent;  state Exp;
  31. branches ;
  32. next     1.2;
  33.  
  34. 1.2
  35. date     86.07.18.10.38.01;  author brent;  state Exp;
  36. branches ;
  37. next     1.1;
  38.  
  39. 1.1
  40. date     86.07.17.13.19.16;  author brent;  state Exp;
  41. branches ;
  42. next     ;
  43.  
  44.  
  45. desc
  46. @Routine to load a program into main memory
  47. @
  48.  
  49.  
  50. 1.7
  51. log
  52. @New include files and constants due to source reorganization
  53. @
  54. text
  55. @/* 
  56.  * fileLoad.c --
  57.  *
  58.  *    The routine to load a program into main memory.
  59.  *
  60.  * Copyright 1986 Regents of the University of California
  61.  * All rights reserved.
  62.  */
  63.  
  64. #ifndef lint
  65. static char rcsid[] = "$Header: fileLoad.c,v 1.6 87/05/27 14:32:39 brent Exp $ SPRITE (Berkeley)";
  66. #endif not lint
  67.  
  68. #include "sprite.h"
  69. #include "fs.h"
  70. #include "procAOUT.h"
  71. #include "machMon.h"
  72.  
  73. #define KERNEL_ENTRY 0x4000
  74.  
  75.  
  76. /*
  77.  *----------------------------------------------------------------------
  78.  *
  79.  * FileLoad --
  80.  *
  81.  *    Read in the kernel object file.  This is loaded into memory at
  82.  *    a pre-defined location (in spite of what is in the a.out header)
  83.  *    for compatibility with Sun/UNIX boot programs.  The Sprite kernel
  84.  *    expects to be loaded into the wrong place and does some re-mapping
  85.  *    to relocate the kernel into high virtual memory.
  86.  *
  87.  * Results:
  88.  *    The entry point.
  89.  *
  90.  * Side effects:
  91.  *    None.
  92.  *
  93.  *----------------------------------------------------------------------
  94.  */
  95.  
  96.  
  97. int
  98. FileLoad(handlePtr)
  99.     register FsHandle    *handlePtr;
  100. {
  101.     Proc_AOUT        aout;
  102.     int            bytesRead;
  103.     register int    *addr;
  104.     register ReturnStatus status;
  105.     register int    i;
  106.     register int    numBytes;
  107.  
  108.     /*
  109.      * Read a.out header.
  110.      */
  111.  
  112.     status = Fs_Read(handlePtr, 0, sizeof(aout), &aout, &bytesRead);
  113.     if (status != SUCCESS || bytesRead != sizeof(aout)) {
  114.     Mach_MonPrintf("No a.out header");
  115.     goto readError;
  116.     } else if (aout.magic != PROC_OMAGIC) {
  117.     Sys_Printf("A.out? mag %x size %d+%d+%d\n",
  118.         aout.magic, aout.code, aout.data, aout.bss);
  119.     return(-1);
  120.     }
  121.  
  122.     /*
  123.      * Read the code.
  124.      */
  125.  
  126.     numBytes = aout.code;
  127.     Mach_MonPrintf("Size: %d", numBytes);
  128.     status = Fs_Read(handlePtr, PROC_CODE_FILE_OFFSET(aout), numBytes,
  129.               KERNEL_ENTRY, &bytesRead);
  130.     if (status != SUCCESS) {
  131.     goto readError;
  132.     } else if (bytesRead != numBytes) {
  133.     goto shortRead;
  134.     }
  135.  
  136.     /*
  137.      * Read the initialized data.
  138.      */
  139.  
  140.     numBytes = aout.data;
  141.     Mach_MonPrintf("+%d", numBytes);
  142.     status = Fs_Read(handlePtr, PROC_DATA_FILE_OFFSET(aout), numBytes,
  143.               KERNEL_ENTRY + aout.code, &bytesRead);
  144.     if (status != SUCCESS) {
  145. readError:
  146.     Mach_MonPrintf("\nRead error <%x>\n", status);
  147.     return(-1);
  148.     } else if (bytesRead != numBytes) {
  149. shortRead:
  150.     Mach_MonPrintf("\nShort read (%d)\n", bytesRead);
  151.     return(-1);
  152.     }
  153.  
  154.     /*
  155.      * Zero out the bss.
  156.      */
  157.  
  158.     numBytes = aout.bss;
  159.     Mach_MonPrintf("+%d\n", numBytes);
  160.     addr = (int *) (KERNEL_ENTRY + aout.code + aout.data);
  161.     for (i = 0; i < numBytes; i += 4, addr++) {
  162.     *addr = 0;
  163.     }
  164.  
  165.     return (KERNEL_ENTRY);
  166. }
  167. @
  168.  
  169.  
  170. 1.6
  171. log
  172. @messed with print statements.
  173. @
  174. text
  175. @d11 1
  176. a11 1
  177. static char rcsid[] = "$Header: fileLoad.c,v 1.5 87/05/11 11:14:56 brent Exp $ SPRITE (Berkeley)";
  178. d14 2
  179. d17 1
  180. a17 3
  181. #include "fs.h"
  182. #include "fsInt.h"
  183. #include "sunMon.h"
  184. d19 1
  185. a19 5
  186. /*
  187.  * The boot program always loads the kernel starting at this location.
  188.  * The kernel will remap itself to where it wants.
  189.  */
  190. #define KERNEL_ENTRY    0x4000
  191. d60 1
  192. a60 1
  193.     Mon_Printf("No a.out header");
  194. d73 1
  195. a73 1
  196.     Mon_Printf("Size: %d", numBytes);
  197. d87 1
  198. a87 1
  199.     Mon_Printf("+%d", numBytes);
  200. d92 1
  201. a92 1
  202.     Mon_Printf("\nRead error <%x>\n", status);
  203. d96 1
  204. a96 1
  205.     Mon_Printf("\nShort read (%d)\n", bytesRead);
  206. d105 1
  207. a105 1
  208.     Mon_Printf("+%d\n", numBytes);
  209. @
  210.  
  211.  
  212. 1.5
  213. log
  214. @Fixed so it always loads to the same place.  Stupid, but compatible
  215. with the Sun/UNIX boot programs so the kernel can deal.
  216. @
  217. text
  218. @d11 1
  219. a11 1
  220. static char rcsid[] = "$Header: fileLoad.c,v 1.4 86/07/24 11:46:42 brent Exp $ SPRITE (Berkeley)";
  221. d67 3
  222. a69 1
  223.     Mon_Printf("need 0%o a.out\n", PROC_OMAGIC);
  224. d109 1
  225. a109 1
  226.     Mon_Printf("+%d", numBytes);
  227. a114 1
  228.     Mon_Printf(" bytes\n");
  229. @
  230.  
  231.  
  232. 1.4
  233. log
  234. @more trimming
  235. @
  236. text
  237. @d11 1
  238. a11 1
  239. static char rcsid[] = "$Header: fileLoad.c,v 1.3 86/07/21 09:33:43 brent Exp $ SPRITE (Berkeley)";
  240. d19 6
  241. d31 5
  242. a35 1
  243.  *    Read in the kernel object file.
  244. a50 1
  245.     
  246. d77 1
  247. a77 1
  248.               aout.entry, &bytesRead);
  249. d91 1
  250. a91 1
  251.               aout.entry + aout.code, &bytesRead);
  252. d108 1
  253. a108 1
  254.     addr = (int *) (aout.entry + aout.code + aout.data);
  255. d114 1
  256. a114 1
  257.     return (aout.entry);
  258. @
  259.  
  260.  
  261. 1.3
  262. log
  263. @Did some scrunching, fixed a bug.
  264. @
  265. text
  266. @d11 1
  267. a11 1
  268. static char rcsid[] = "$Header: fileLoad.c,v 1.2 86/07/18 10:38:01 brent Exp $ SPRITE (Berkeley)";
  269. d47 1
  270. d54 5
  271. a58 4
  272.     if (status != SUCCESS || bytesRead != sizeof(aout) ||
  273.     PROC_BAD_MAGIC_NUMBER(aout)) {
  274.     Mon_Printf("Bad a.out format\n");
  275.     return(-1);
  276. d65 7
  277. a71 5
  278.     Mon_Printf("Sprite size: %d", aout.code);
  279.     status = Fs_Read(handlePtr, PROC_CODE_FILE_OFFSET(aout), aout.code,
  280.               PROC_CODE_LOAD_ADDR(aout), &bytesRead);
  281.     if (status != SUCCESS ||
  282.     bytesRead != aout.code) {
  283. d79 9
  284. a87 5
  285.     Mon_Printf("+%d", aout.data);
  286.     status = Fs_Read(handlePtr, PROC_DATA_FILE_OFFSET(aout), aout.data,
  287.               PROC_DATA_LOAD_ADDR(aout), &bytesRead);
  288.     if (status != SUCCESS ||
  289.     bytesRead != aout.data) {
  290. d89 1
  291. a89 1
  292.     Mon_Printf("\nShort read\n");
  293. d97 4
  294. a100 3
  295.     Mon_Printf("+%d", aout.bss);
  296.     addr = (int *) PROC_BSS_LOAD_ADDR(aout);
  297.     for (i = 0; i < aout.bss; i += 4, addr++) {
  298. d105 1
  299. a105 1
  300.     return (PROC_CODE_LOAD_ADDR(aout));
  301. @
  302.  
  303.  
  304. 1.2
  305. log
  306. @name change
  307. @
  308. text
  309. @d11 1
  310. a11 1
  311. static char rcsid[] = "$Header: fileLoad.c,v 1.1 86/07/17 13:19:16 brent Exp $ SPRITE (Berkeley)";
  312. d39 1
  313. a39 1
  314.     FsHandle    *handlePtr;
  315. d44 3
  316. a46 3
  317.     int            *addr;
  318.     ReturnStatus    status;
  319.     int            i;
  320. d55 1
  321. a55 1
  322.     Mon_Printf("Couldn't read a.out format\n");
  323. d66 3
  324. a68 3
  325.     if (status != SUCCESS) {
  326.     Mon_Printf("\nCould not read code\n");
  327.     return(-1);
  328. a69 4
  329.     if (bytesRead != aout.code) {
  330.     Mon_Printf("\nShort read\n");
  331.     return(-1);
  332.     }
  333. d76 1
  334. a76 1
  335.     status = Fs_Read(handlePtr, PROC_DATA_FILE_OFFSET(aout), aout.code,
  336. d78 3
  337. a80 5
  338.     if (status != SUCCESS) {
  339.     Mon_Printf("\nCould not read initialized data\n");
  340.     return(-1);
  341.     }
  342.     if (bytesRead != aout.code) {
  343. @
  344.  
  345.  
  346. 1.1
  347. log
  348. @Initial revision
  349. @
  350. text
  351. @d11 1
  352. a11 1
  353. static char rcsid[] = "$Header: proto.c,v 1.4 86/03/20 14:00:11 andrew Exp $ SPRITE (Berkeley)";
  354. d52 1
  355. a52 1
  356.     status = BootRead(handlePtr, 0, sizeof(aout), &aout, &bytesRead);
  357. d64 1
  358. a64 1
  359.     status = BootRead(handlePtr, PROC_CODE_FILE_OFFSET(aout), aout.code,
  360. d80 1
  361. a80 1
  362.     status = BootRead(handlePtr, PROC_DATA_FILE_OFFSET(aout), aout.code,
  363. @
  364.